package com.app.teaware.bean;

import android.text.TextUtils;

import com.app.teaware.util.UnitUtil;

import java.util.ArrayList;
import java.util.List;

import my.MathUtils;

public class GoodsSubmitData extends BasisBean {

    /**
     * {
     *   "workm": {
     *     "aid": "string",
     *     "bfs": "string",
     *     "cid": "string",
     *     "cna": "string",
     *     "mdt": "yyyy-MM-dd",
     *     "mht": "string",
     *     "mid": "string",
     *     "mna": "string",
     *     "mno": "string",
     *     "mty": "string",
     *     "nch": "string",
     *     "tys": "string",
     *     "udt": "yyyy-MM-dd",
     *     "una": "string",
     *     "uno": "string",
     *     "upm": "string",
     *     "wch": "string",
     *     "wno": "string"
     *   },
     *   "works": [
     *     {
     *       "aid": "string",
     *       "bfs": "string",
     *       "cid": "string",
     *       "gid": "string",
     *       "gna": "string",
     *       "gno": "string",
     *       "gnu": 0,
     *       "gsp": "string",
     *       "gun": "string",
     *       "gwt": 0,
     *       "mdt": "yyyy-MM-dd",
     *       "mid": "string",
     *       "rfid": "string",
     *       "sid": "string",
     *       "wms": "string",
     *       "wno": "string"
     *     }
     *   ]
     * }
     */
    private static final long serialVersionUID = 1L;


    private GoodsWorkm workm;
    private List<GoodsWorks> works;

    public GoodsWorkm getWorkm() {
        return workm;
    }

    public void setWorkm(GoodsWorkm workm) {
        this.workm = workm;
    }

    public List<GoodsWorks> getWorks() {
        if(works == null){
            works = new ArrayList<>();
        }
        return works;
    }

    public void setWorks(List<GoodsWorks> works) {
        this.works = works;
    }


    public String getWeight(){
        String weight = "0";
        List<GoodsWorks> worksList =  getWorks();
        for (GoodsWorks work : worksList){
            double a = UnitUtil.getRatio(work.getGun(),"g");
//            boolean isSameUtil = a > 1;
//            if(isSameUtil){
                weight = MathUtils.add(weight,MathUtils.multiply(work.getGwt(),String.valueOf(a)));
//            }else {
//                weight = MathUtils.add(weight,work.getGwt());
//            }

        }
        return weight;
    }

    public String getNum(){
        String num = "0";
        List<GoodsWorks> worksList =  getWorks();
        for (GoodsWorks work : worksList){
            if(!TextUtils.isEmpty(work.getGnu())) {
                num = MathUtils.add(num, work.getGnu());
            }
        }
        return num;
    }


    public String getAllWbx(){      //获取到所有纸箱重量
        String num = "0";
        List<GoodsWorks> worksList =  getWorks();
        if(worksList == null || worksList.size()<1){
            return num;
        }
        for (GoodsWorks work : worksList){
            if(!TextUtils.isEmpty(work.getWbx())){
                num = MathUtils.add(num,work.getWbx());
            }
        }
        return num;
    }


    public String getMinWcz(){          //获取最小的误差值
        String cyz = "10000";
        List<GoodsWorks> worksList =  getWorks();
        if(worksList == null || worksList.size()<1){
            return cyz;
        }
        for (GoodsWorks work : worksList){
            cyz = MathUtils.compareToGetMinValue(cyz,work.getDbx());
        }
        return cyz;
    }


}
